/*************************************************************************
	> File Name: B4007.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-04-16 13:06:34
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int get(vector<int> &num, int l, int r) {
    int ans = 0;
    for (int i = l; i <= r; i++) {
        ans = ans * 10 + num[i];
    }
    return ans;
}

int p(vector<int> &num, int ind) {
    int ans = 1;
    for (int i = ind; i < num.size(); i++) {
        ans *= 10;
    }
    return ans;
}

int dp(int n, int x) {
    vector<int> num;
    do {
        num.push_back(n % 10);
        n /= 10;
    } while (n);
    reverse(num.begin(), num.end());
    int ans = 0;
    for (int i = !x; i < num.size(); i++) {
        if (i != 0) ans += (get(num, 0, i - 1) - !x) * p(num, i + 1);
        if (x == num[i]) ans += get(num, i + 1, num.size() - 1) + 1;
        else if (x < num[i]) ans += p(num, i + 1);
    }
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << dp(n, k) << endl;
    return 0;
}
